﻿namespace Dyao.Book.Contract
{
    /// <summary>
    /// 任务中心参数
    /// </summary>
    public interface ITaskCenterParameters
    {
        /// <summary>
        /// 是否存在key
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        bool IsExists(string key);

        /// <summary>
        /// 尝试获取值，返回是否获取成功
        /// </summary>
        /// <param name="key">参数key</param>
        /// <param name="value">值</param>
        /// <returns>是否获取成功</returns>
        bool TryGetValue(string key, out object value);

        /// <summary>
        /// 尝试获取值，返回是否获取成功
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        bool TryGetValue<T>(string key, out T value);

        /// <summary>
        ///  尝试将原始参数值转换为 <typeparamref name="T"/> <paramref name="model"/>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        /// <returns></returns>
        bool TryDeserializeParametersTo<T>(out T model);

        /// <summary>
        /// 反序列化
        /// </summary>
        /// <param name="type"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        object Deserialize(Type type, object value);

        /// <summary>
        /// 获取所有key
        /// </summary>
        /// <returns></returns>
        IEnumerable<string> GetKeys();

        /// <summary>
        /// 变成为字符串
        /// </summary>
        /// <returns></returns>
        string ToString();
    }

    /// <summary>
    /// 任务中心参数
    /// </summary>
    /// <typeparam name="T">参数model类型</typeparam>
    public interface ITaskCenterParameters<T> : ITaskCenterParameters
        where T : class
    {
        /// <summary>
        /// model
        /// </summary>
        public T Model { get; }
    }
}
